#include "qtquickro_plugin.h"

#include <QMetaType>
#include <qqml.h>

#include "ROComponent.h"
#include "ROHost.h"
#include "RONode.h"
#include "ROPlayer.h"
#include "RORPC.h"
#include "ROLoader.h"
#include "ROExportProperty.h"
#include "ROSharedObject.h"
#include "ROHelper.h"
#include "ROPlayerValidator.h"
#include "QQuickROData.h"
#include "ROPropertyUpdater.h"
#include "ROTriggeredUpdater.h"
#include "ROFramedUpdater.h"

template<typename T>
QObject* createInstance(QQmlEngine *engine, QJSEngine *scriptEngine){
    return new T();
}

void QtQuickROPlugin::registerTypes(const char *uri)
{
    qRegisterMetaType<CreationInfo>();
    qRegisterMetaType<ROId>();
    qRegisterMetaType<QList<ROComponent *>>();
    // @uri QtQuick3DUtils
    qmlRegisterUncreatableType<ROSyncCreation>(uri,1,0,"ROSyncCreation","This is an abstract Class");
    qmlRegisterType<ROComponent>(uri,1,0,"ROComponent");
    qmlRegisterType<ROLoader>(uri,1,0,"ROLoader");
    qmlRegisterType<ROHost>(uri,1,0,"ROHost");
    qmlRegisterType<RONode>(uri,1,0,"RONode");
    qmlRegisterType<ROPlayer>(uri,1,0,"ROPlayer");
    auto helper = ROHelper::instance();
    helper->moveToThread(qApp->thread());
    qmlRegisterSingletonInstance<ROHelper>(uri,1,0,"ROHelper",helper);
    qmlRegisterType<ROPlayerValidator>(uri,1,0,"ROPlayerValidator");

    qmlRegisterUncreatableType<ROSyncObject>(uri,1,0,"ROSyncObject","This is an abstract Class");
    qmlRegisterType<RORPC>(uri,1,0,"RORPC");

    qmlRegisterUncreatableType<ROSyncProperty>(uri,1,0,"ROSyncProperty","This is an abstract Class");
    qmlRegisterType<ROExportProperty>(uri,1,0,"ROExportProperty");
    qmlRegisterType<ROSharedObject>(uri,1,0,"ROSharedObject");

    qmlRegisterUncreatableType<ROPropertyUpdater>(uri,1,0,"ROPropertyUpdater","This is an abstract Class");
    qmlRegisterType<ROTriggeredUpdater>(uri,1,0,"ROTriggeredUpdater");
    qmlRegisterType<ROFramedUpdater>(uri,1,0,"ROFramedUpdater");
}

